//
//  YDAMineLoginTopView.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/26.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDAMineLoginTopView.h"

@interface YDAMineLoginTopView()

//背景图片
@property (nonatomic , weak) UIImageView *backImage;
//标题
@property (nonatomic , weak) UILabel *titleLabel;
//用户头像
@property (nonatomic , weak) UIImageView *iconImageView;
//用户手机号
@property (nonatomic , weak) UILabel *userAccountLabel;

@end

@implementation YDAMineLoginTopView


-(void)setDict:(NSDictionary *)dict
{
    _dict = dict;
    
    NSString *phoneString = [dict objectForKey:@"phone"];
    if (phoneString.length) {
        self.userAccountLabel.text = [NSString phoneNumberasterisk:phoneString];
    }
    
    NSString *iconUrl = dict[@"headPortrait"];
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:iconUrl] placeholderImage:[UIImage imageNamed:@"wd-touxiang"]];
    
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.userInteractionEnabled = YES;
        [self backImage];
        [self titleLabel];//标题
        [self iconImageView];//用户头像
        [self userAccountLabel];//用户账号   用户账号文字之间加字间距1.0
        
        
    }
    return self;
}

+(instancetype)mineLoginTopViewInitWithFrame:(CGRect)frame andDict:(NSDictionary *)dict
{
    YDAMineLoginTopView *topView = [[self alloc] initWithFrame:frame];
    topView.dict = dict;
    return topView;
}
/*****背景图片******/
-(UIImageView *)backImage
{
    if (_backImage == nil) {
        UIImageView *backImage = [[UIImageView alloc] init];
        [self addSubview:backImage];
        backImage.image = [UIImage imageNamed:@"wode-bg-yd"];
        backImage.contentMode = UIViewContentModeScaleToFill;
        [backImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.equalTo(self);
        }];
        _backImage = backImage;
    }
    return _backImage;
}
/*****标题******/
-(UILabel *)titleLabel
{
    if (_titleLabel == nil) {
        UILabel *titleLabel = [[UILabel alloc] init];
        [self addSubview:titleLabel];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.font = [UIFont systemFontOfSize:font20ScreenWRate * LKScreenW];
        titleLabel.text = @"我的";
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(37));
            }else{
                make.top.equalTo(self).offset(rate750(27));
            }
            
        }];
        
        _titleLabel = titleLabel;
    }
    return _titleLabel;
}
/*****用户头像******/
-(UIImageView *)iconImageView
{
    if (_iconImageView == nil) {
        UIImageView *iconImageView = [[UIImageView alloc] init];
        [self addSubview:iconImageView];
        iconImageView.image = [UIImage imageNamed:@"wd-touxiang"];
        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.width.equalTo(@(rate375(60)));
            make.centerX.equalTo(self);
            if (isPhoneX) {
                make.top.equalTo(self.titleLabel.mas_bottom).offset(rateX812(18));
            }else{
                make.top.equalTo(self.titleLabel.mas_bottom).offset(rate750(18));
            }
        }];
        iconImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
        [iconImageView addGestureRecognizer:tap];
        iconImageView.layer.cornerRadius = rate375(60) * 0.5;
        iconImageView.layer.masksToBounds = YES;
        
        _iconImageView = iconImageView;
    }
    return _iconImageView;
}
/*****用户账号******/
-(UILabel *)userAccountLabel
{
    if (_userAccountLabel == nil) {
        UILabel *userAccountLabel = [[UILabel alloc] init];
        [self addSubview:userAccountLabel];
        userAccountLabel.textAlignment = NSTextAlignmentCenter;
        userAccountLabel.textColor = [UIColor whiteColor];
        userAccountLabel.font = [UIFont systemFontOfSize:font20ScreenWRate * LKScreenW];
        userAccountLabel.text = @"138****3838";
        [userAccountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            if (isPhoneX) {
                make.top.equalTo(self.iconImageView.mas_bottom).offset(rateX812(18));
            }else{
                make.top.equalTo(self.iconImageView.mas_bottom).offset(rate750(18));
            }
            
        }];
        userAccountLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
        [userAccountLabel addGestureRecognizer:tap];
        _userAccountLabel = userAccountLabel;
    }
    return _userAccountLabel;
}

-(void)tapClick
{
    DDLog(@"==========")
    if ([self.delegate respondsToSelector:@selector(aMineLoginTopView:clickStyle:)]) {
        [self.delegate aMineLoginTopView:self clickStyle:SYAMineLoginTopViewClickAcc];
    }
}




@end
